package com.ty.user.starter.util;

import org.springframework.util.Assert;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

/**
 * 会话工具类
 *
 * @author minku
 * @date 2021-10-20
 */
public class SessionUtils {

    public static final String RSA_KEY = "rsaKey";

    private SessionUtils() {
    }

    public static RequestAttributes getRequestAttributes() {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        Assert.notNull(requestAttributes, String.format("获取关联属性对象[%s]失败", "RequestAttributes"));
        return requestAttributes;
    }

    public static HttpSession getSession() {
        return ((ServletRequestAttributes)getRequestAttributes()).getRequest().getSession();
    }
}
